<?php
namespace app\index\controller;

use app\BaseController;
use app\common\model\Category;
use think\facade\Db;

class Index extends Base
{
    public function index()
    {

        $bannerData = Db::name('ad')->where('type_id',1)->select();

        $goodsData5 = Db::name('goods')->where('ishot',1)->limit(8)->order('goods_id desc')->order('listorder asc')->where('goods_status',1)->select();

        $category_model = new Category();
        $indexCate=$category_model->getNavCateData();

        return view('',[

            'goodsData5'=>$goodsData5,
            'web_title' => "商城",
            'indexCate'=>$indexCate,
            'bannerData'=>$bannerData
        ]);

    }

    //优惠券专题
    public function coupons()
    {
        //不能获取已经过期的优惠券
        $time=time();
        $couponsData=Db::name('coupons')->order('id desc')->where('time2','>',$time)->select();
        return view('',[
            'couponsData'=>$couponsData
        ]);
    }

    //表单令牌
    public function message(Request $request){
        if(request()->isPost()){
            $data=input('post.');
            $check = $request->checkToken('__token__');
            if(false === $check) {

                throw new ValidateException('invalid token');
            }
            echo '令牌正确，请插入数据表';
        };
        return view();
    }
}
